let tool = require('./tool.js');


//获取我的个人信息
export function getUserDetail(data) {
  return post('user/getuserinfo', data);
}

//获取学习汇报列表
export function getAccessList(data) {
  return post('projectReview/learnInfo', data);
}

//获取汇报详情
export function getAccessDetail(data) {
  return post('projectReview/feedbackinfo', data);
}

//21抗遗忘复习（日历）
export function getAntiForgetData(data) {
  return post('projectReview/antiforget', data);
}

//获取今日需复习的单词（学后检测）
export function getTodayReviewList(data) {
  return post('projectReview/getreviewwords', data);
}

//今日复习检测提交（学后检测提交）
export function submitReviewWords(data) {
  return post('projectReview/updatereviewwords', data);
}

//我的学习记录列表
export function getStudyRecordList(data) {
  return post('projectReview/learningrecords', data);
}
//学习记录详情
export function getStudyRecordDetail(data) {
  return post('projectReview/learningrecordsdetails', data);
}

//获取支付信息
export function getPayinfo(data) {
  return post('user/getpayinfo', data);
}

//开通会员
export function tovip(data) {
  return post('user/tovip', data);
}

//获取支付结果
export function checkPayStatus(data) {
  return post('user/checkstatus', data);
}

//获取首页数据
export function getIndexData(data) {
  return post('user/index', data);
}

//查看21方格今日复习后的错词列表
export function getAntiWrongWords(data) {
  return post('projectReview/geterrwords', data);
}

//获取单词学习时间列表
export function getWordStudytimeList(data) {
  return post('review/getstudytime', data);
}

/////////////////语法写作/////////////////////////////
//语法复习提交
export function submitGrammar(data) {
  return post('projectReview/submitgrammer', data);
}

export function getGrammarList(data) {
  return post('grammar/train', data);
}

export function submitGrammarAnswer(data) {
  return post('grammar/trainSub', data);
}

export function lookError(data) {
  return post('grammar/checkerrbyday', data);
}

//获取必备范文详情
export function getessaydetail(data) {
  return post('projectReview/essaydetail', data);
}

//获取词组详情
export function getphraseDetail(data) {
  return post('projectReview/phraselist', data);
}

//获取万能句型列表
export function getsentencelist(data) {
  return post('projectReview/sentencelist', data);
}

//范文仿写要求
export function getessayrequire(data) {
  return post('projectReview/essayrequirement', data);
}

//拍照上传范文
export function uploadPic(data){
  return post('common/upload',data);
}

//提交范文作业
export function uploadEssayWork(data) {
  return post('projectReview/uploadessay', data);
}

//作文家庭作业列表
export function getEssayHomeWork(data) {
  return post('projectReview/homework', data);
}


////////////////单词速记模块//////////////////////////////
//获取可用词库
export function getwordpackages(data){
  return post('word/wordpackages',data);
}

//获取九宫格状态
export function getBoxsStatus(data) {
  return post('word/wordpackagestatus', data);
}
//获取当前词库
export function getCurrentCourse(data) {
  return post('/word/index', data);
}
//请求获取选词数据 点start请求的
export function getSelectData(data) {
  return post('/word/reciteword4', data);
} 
//获取盒子里的单词 type(difficult  complete  easy)
export function getBoxWords(data) {
  return post('/word/squareword', data);
}
//自主复习
export function getIndpendentreviewWords(data) {
  return post('/word/getreviewwords', data);
}

//开始下一轮
export function startnext(data) {
  return post('/word/startnext', data);
}
//提交一眼会和不会的 times 1学前检测 2学后检测 f_type 0下一页 1开始识记 type init识记 review复习
export function referWord(data) {
  return post('/word/distinguishword4', data);
}

//提交打印 word_list from "word_remember" question_type 0
export function prints(data) {
  return post('/word/prints', data);
}
//学习报告
export function getreport(data) {
  return post('/word/getreport', data);
}

//加载课程包
export function checkhasword(data) {
  return post('/word/checkhasword', data);
}

//加入生词本
export function addhardWord(data){
  return post('word/addword',data);
}
//结束识记
export function stopStudy(data){
  return post('word/stopstudy',data);
}

//获取学习渠道
export function getCheckTag(data) {
  return post('user/checkTag', data);
}

//领取公益课
export function getPublicCourse(data) {
  return post('index/getcourse', data);
}
//开始计时
export function startTime(data) {
  return post('/index/starttime', data);
}
//结束计时
export function stopTime(data) {
  return post('/index/stoptime', data);
}
///////////督学系统（复习)////////////
//获取今日复习任务
export function getReviewTask(data) {
  return post('supervision/getreview', data);
}

//获取单词复习任务
export function getWordReviewTask(data) {
  return post('supervision/getreviewwords', data);
}

//获取单词复习---词义闯关的形式
export function getWordMeanReview(data) {
  return post('supervision/getreviewmeaning', data);
}

// 获取单词复习---听音识义
export function getWordListenReview(data) {
  return post('supervision/getreviewlisten', data);
}

// 获取单词复习---对对碰
export function getWordPopReview(data) {
  return post('supervision/getreviewpop', data);
}
// 获取单词复习---组合拼
export function getWordComposeReview(data) {
  return post('supervision/getreviewcompose', data);
}

//获取单词复习---学后检测
export function getReviewCheckPass(data) {
  return post('supervision/getreviewcheckpass', data);
}

//查看单词复习错词
export function getErrorWord(data) {
  return post('supervision/errwords', data);
}

//获取阅读复习关卡列表
export function getReadReviewList(data) {
  return post('supervision/getreadlist', data);
}


//获取阅读复习任务详情
export function getReadReviewDetail(data) {
  return post('supervision/readdetail', data);
}

//获取语法复习句子列表
export function getGrammerReview(data) {
  return post('supervision/getreviewgrammar', data);
}

//获取写作复习任务
export function getEssayReview(data) {
  return post('supervision/getreviewessay', data);
}

//获取复习记录
export function getReviewRecordList(data) {
  return post('supervision/getreviewlist', data);
}

//提交单词作业
export function submitWordReview(data) {
  return post('supervision/submitwords', data);
}

//四种玩法查看单词错词
export function lookErrorWords(data) {
  return post('supervision/errwords', data);
}

//提交阅读和写作作业
export function submitRWReview(data) {
  return post('supervision/submitread', data);
}

//提交语法图片和声音作业
export function submitGrammarReview(data) {
  return post('supervision/submitgrammar', data);
}

//查看督学复习玩法的作业报告 复习类型type 0 单词 1 阅读 3 语法 4 写作
export function getWorkReport(data) {
  return post('supervision/getreviewreport', data);
}


//get请求
export function get(...args) {
  return request('GET', ...args)
}

// post 请求
export function post(...args) {
  return request('POST', ...args)
}


// 网络请求
export function request(method, url, data) {
  if (!data) {
    data = {}
  }
  // let rs = tool.getSign(data, getApp().globalData.key, method); //返回 bodyParam heaer sign
  let rs = tool.getSign(data, getApp().globalData.key); //返回 bodyParam heaer sign
  console.log(`接口: ${url} 请求参数, `, data)
  return new Promise((resolve, reject) => {
    wx.request({
      url: getApp().globalData.apiURL + url + '?sign=' + rs.sign,
      header: rs.header,
      method: method,
      data: data,
      success: function(res) {
        // console.log(`接口: ${url} 调用成功, ${JSON.stringify(res)}`);
        wx.hideLoading()
        if (res.data.code === 1) {
          resolve(res.data)
        } else if (res.data.code === 10001) {
          wx.reLaunch({
            url: '/pages/login/login',
          })
        } else {
          setTimeout(function () {
            wx.showToast({
              title: res.data.info,
              icon: 'none',
              duration: 2000
            });
          }, 300)
        }
      },
      fail: function(err) {
        wx.hideLoading()
        wx.showModal({
          title: '温馨提示',
          content: '网络异常请稍后再试',
        })
        console.log(`接口: ${url} 调用失败, `, err)
        reject(err)
      },
      complete: function() {
        wx.hideLoading();
      }
    })
  })
}